﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cloud.Model;
using Cloud.BLL;


public partial class Three_Managerment_Problem_one_Scwj : System.Web.UI.Page
{
    public String fnname ="";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

        if (Session["users"] == null)
        {
            Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["type"].Equals("add"))
            {
                this.name.Value = ((USER_INFO)Session["users"]).USER_NAME;
                this.date.Value = DateTime.Now.ToString("yyyy-MM-dd");
                this.filename.Visible = false;

            }
            else
            {
                this.savesbtn.Visible = false;
                this.file.Visible = false;
                Files fis = FilesManager.FindById(Convert.ToInt32(Request.QueryString["id"]));
                this.name.Value = fis.Scr;
                this.date.Value = fis.Scrq.ToString();
                this.title.Value = fis.Zt;
                 fnname =fis.Scwj;
                 filename.HRef = fnname;
            }
           
        }
        }
        catch (Exception ex)
        {

            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }

    protected void Unnamed_Click(object sender, EventArgs e)
    {
        try
        {

        Random ran = new Random();
        int RandKey = ran.Next(10000, 99999);
        string path = Server.MapPath("~/upload/");
        Files activity = new Files();
        activity.Scr = ((USER_INFO)Session["users"]).USER_NAME;
        activity.Scrq = DateTime.Now;
        activity.Zt = this.title.Value;
        String filenames = DateTime.Now.ToString("yyyyMMddhhmmss") + RandKey;
        String[] hz = file.FileName.ToString().Split('.');
        filenames = filenames + "." + hz[hz.Length - 1];
        if (this.file.HasFile)
        {
            file.PostedFile.SaveAs(path + filenames);
            activity.Scwj = "/upload/" + filenames;
        }
        else
        {
            activity.Scwj = "";
        }

        if (FilesManager.Save(activity)>0)
        {
            Response.Write("<script>alert('上传成功'); location.href='index.aspx'</script>");
        }
        else 
        {
            Response.Write("<script>alert('上传失败'); </script>");
            return;
        }
        }
        catch (Exception ex)
        {

            Response.Write("<script>alert('登陆信息失效,请重新登陆!'); window.parent.location.href='/index.html'</script>");
            return;
        }
      
    }
}